
#include "computeTime.h"

int getTime_self_thermal()
{
    /*
    return us
    */
    struct timeval tv;

    int time;
    gettimeofday(&tv,NULL);
    time = tv.tv_sec*1000000 + tv.tv_usec;  //us

    return time;
}

//ThirdPart: #include "computeTime.h"
void getLocalTime_self_thermal(char* buf, size_t size){
    //char buffer[50];
    char* &buffer1 = buf;

    struct timeval tv; 
    struct tm now_time;

    gettimeofday(&tv, NULL);
    //printf("%ld\n", tv.tv_sec);

     localtime_r(&tv.tv_sec, &now_time);
    // printf("%d-%d-%d %d-%d-%d\n", now_time.tm_year+1900, now_time.tm_mon+1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec);

    snprintf(buffer1, 60, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", now_time.tm_year+1900, now_time.tm_mon+1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec);
    //printf("%s\n", buffer1);

    return;
}

//#include <ctime>
string getLocalTime_self_thermal()
{
    // 基于当前系统的当前日期/时间
	time_t now = time(0);

	// 把 now 转换为 tm 结构
	tm *gmtm = localtime(&now);
	//cout << gmtm->tm_year+1900 << "年" << gmtm->tm_mon+1 << "月" << gmtm->tm_mday << "日" << gmtm->tm_hour << ":" << gmtm->tm_min << ":" << gmtm->tm_sec<<endl;

    char buffer[60];
    snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%02d %.2d:%.2d:%.2d", gmtm->tm_year+1900, gmtm->tm_mon+1, gmtm->tm_mday, gmtm->tm_hour,gmtm->tm_min, gmtm->tm_sec);

    string str = buffer;
    return buffer;
}

// 结果：
// kayshi@ubuntu:~/code/Test$ ./a.out 
// runpp, 10
// 1602834778
// 2020-10-16 15-52-58
// 2020-10-16 15-52-58

